﻿<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of errorclass
 *
 * @author at8eqeq3
 */
class error {

    public $file;
    public $line;
    public $message;
    public $critical;
    private $phperr;
    private $mysqlerr;

    public function __construct($f, $l, $m = "Произошла какая-то ошибка", $c = false){
        $this->file = $f;
        $this->line = $l;
        $this->message = $m;
        $this->critical = $c;
        if(isset($php_errormsg)){
            $this->phperr = $php_errormsg;
        }
        if(mysql_error() && mysql_errno()){
            $this->mysqlerr = mysql_errno().' '.mysql_error();
        }
    }

    public function raise(){
        $out = "<div class=\"error\"><b>Произошла ошибка</b><br />\n";
        if(ERRMSGLEVEL >= 1){
            $out .= "$this->message<br />\n";
        }
        if(ERRMSGLEVEL >= 2){
            $out .= "<b>Источник:</b> $this->file, <b>строка:</b> $this->line<br />\n";
            if($this->phperr){
                $out .= "<b>PHP сказал:</b> $this->phperr<br />\n";
            }
            if($this->mysqlerr){
                $out .= "<b>MySQL сказал:</b> $this->mysqlerr<br />\n";
            }
        }
        if(ERRMSGLEVEL >= 3){
            $out .= "<b>Дамп глобальных переменных:</b><br />\n <pre>";
            $out .= "GET:\n".walkarray($_GET)."\n=====\n";
            $out .= "POST:\n".walkarray($_POST)."\n=====\n";
            $out .= "ENV:\n".walkarray($_ENV)."\n=====\n";
            $out .= "SERVER:\n".walkarray($_SERVER)."\n=====\n";
            $out .= "</pre>";
        }
        $out .= "</div>";
        echo $out;
        if($this->critical){
            die("<div class=\"error\">Работа сценария остановлена</div>");
        }
    }
}
?>
